package lab03;

import java.io.*;
import java.util.Scanner;

public class Test05 {
    public static void main(String[] args) {
        File file = new File("E://5.txt");
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println("输入需要加密的字符串：");
        Scanner scanner=new Scanner(System.in);
        String string = scanner.next();

        char[] a = new char[string.length()];
        char[] b = new char[string.length()];
        a = string.toCharArray();

        try {
            FileWriter fileWriter = new FileWriter(file);

            System.out.println("加密后：");

            for (int i = 0; i < a.length; i++) {
                int c = (int) (a[i] + 1);
                b[i] = (char) c;

                System.out.print(b[i]);
            }

            fileWriter.write(b);
            fileWriter.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println();
        System.out.println("解密后：");

        FileReader fileReader = null;

        try {
            fileReader = new FileReader(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        int n = 0;
        try {
            while ((n = fileReader.read()) != -1)

                System.out.print((char) (n - 1));

        } catch (IOException e1) {
            e1.printStackTrace();
        } finally {
            try {
                fileReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
